<template>
  <layout-basic-page>
    <cs-empty :mode="mode">
      <el-button
        type="primary"
        plain
        @click="returnHomePage"
      >
        返回首页
      </el-button>
      <el-button
        type="primary"
        @click="back"
      >
        返回上一页
      </el-button>
    </cs-empty>
  </layout-basic-page>
</template>
<script setup lang="ts">
  import { useRoute, useRouter } from 'vue-router'
  import type { CsEmptyProps } from 'csui'

  defineOptions({ name: 'PageError' })

  const route = useRoute()
  const router = useRouter()

  const returnHomePage = () => {
    router?.replace('/')
  }

  const back = () => {
    router?.back()
  }

  let mode: CsEmptyProps['mode']

  if (route.params.error === '403') {
    mode = 'permission'
  } else if (route.params.error === '404') {
    mode = '404'
  } else {
    mode = 'offline'
  }
</script>
